# Author:Li
import requests

import json


def send_single_sms(apikey, code, moblie):
    """
    发送单条短信
    :param apikey:
    :param code: 验证码
    :param moblie: 发送的手机号
    :return:
    """
    # url = "https://sms.yunpian.com/v2/sms/single_send.json"
    # text = f"【李浩文】您的验证码是{code}。如非本人操作，请忽略本短信"
    # 模板

    # res = requests.post(url, data={
    #     "apikey": apikey,
    #     "mobile": moblie,
    #     "text": text
    # })
    # res_json = json.loads(res.text)
    # 返回json格式的返回值，详情见api文档，将json解析为python对象，可以使用返回值的反馈信息进行下一步操作
    dic_text = {"code": 0, "msg": "发送成功"}
    text = json.dumps(dic_text)
    res_json = json.loads(text)
    return res_json


if __name__ == '__main__':
    res = send_single_sms("apikey", "password", "手机号")
    # res_json = json.loads(res.text)
    # code = res_json["code"]
    # msg = res_json["msg"]
    code = res["code"]
    msg = res["msg"]
    if code == 0:
        print("发送成功")
    else:
        print(f"发送失败: {msg}")
    # print(res.text)
    # res.text获取request返回的response的值

